package Day2025_02_22;

public class LeetCode34 {
    public int[] searchRange(int[] nums, int target) {
        int[] arr = new int[]{-1, -1};
        int n = nums.length;
        int left = 0, right = n - 1;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            int tmp = nums[mid];
            if (tmp < target) left = mid + 1;
            else if (tmp > target) right = mid - 1;
            else {
                while (mid > 0 && nums[mid - 1] == target) mid--;
                arr[0] = mid;
                while (mid < n - 1 && nums[mid + 1] == target) mid++;
                arr[1] = mid;
                break;
            }
        }
        return arr;
    }

    public static void main(String[] args) {
        LeetCode34 leetCode34 = new LeetCode34();
        System.out.println(leetCode34.searchRange(new int[]{5, 7, 7, 8, 8, 10}, 8));
    }
}
